package com.allinpay.merchantweb.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.allinpay.merchantweb.common.utils.SequenceUtil;
import com.allinpay.merchantweb.constants.ReturnCodeConstants;
import com.allinpay.merchantweb.model.EmployeeInfo;
import com.allinpay.merchantweb.model.EnterpriseProdInfoVo;
import com.allinpay.merchantweb.request.CommonReqBean;
import com.allinpay.merchantweb.response.AppCommonResponse;
import com.allinpay.merchantweb.response.ResponseData;
import com.allinpay.merchantweb.service.IEmployeeInfoService;
import com.google.gson.reflect.TypeToken;

@Service
public class EmployeeInfoServiceImpl implements IEmployeeInfoService{

	@Autowired
	RestRequestService restRequestService;
	
	@Override
	public ResponseData<EmployeeInfo> queryEmployeeInfoList(EmployeeInfo employeeInfo) throws Exception {
		// TODO Auto-generated method stub
		CommonReqBean reqBean = new CommonReqBean(); 
		reqBean.setBizContent(employeeInfo);
		reqBean.setReqSsn(SequenceUtil.getAppReqSsn());
		
		
		AppCommonResponse<ResponseData<EmployeeInfo>> respBean = restRequestService.postToAppForSingleByObj
				("/employee/queryEmployeeInfoList"
						, reqBean
						, new TypeToken<AppCommonResponse<ResponseData<EmployeeInfo>>>() {}.getType());
		if( respBean != null &&  respBean.getSubCode() != null 
				&& respBean.getSubCode().equals(ReturnCodeConstants.SUB_CODE_SUCC)) {			

			return respBean.getData();
		}else {
			throw new Exception("queryEmployeeInfoList error:" + respBean.getSubMsg());
		}
	}

	@Override
	public Object addEmployeeInfo(EmployeeInfo employeeInfo) throws Exception {
		// TODO Auto-generated method stub
		CommonReqBean reqBean = new CommonReqBean(); 
		reqBean.setBizContent(employeeInfo);
		reqBean.setReqSsn(SequenceUtil.getAppReqSsn());
		
		
		AppCommonResponse<ResponseData> respBean = restRequestService.postToAppForSingleByObj
				("/employee/addEmployeeInfo"
						, reqBean
						, new TypeToken<AppCommonResponse<ResponseData>>() {}.getType());
		if( respBean != null &&  respBean.getSubCode() != null 
				&& respBean.getSubCode().equals(ReturnCodeConstants.SUB_CODE_SUCC)) {			

			return respBean.getData();
		}else {
			throw new Exception("addEmployeeInfo error:" + respBean.getSubMsg());
		}
	}

	@Override
	public Object updateEmployeeInfo(EmployeeInfo employeeInfo) throws Exception {
		// TODO Auto-generated method stub
		CommonReqBean reqBean = new CommonReqBean(); 
		reqBean.setBizContent(employeeInfo);
		reqBean.setReqSsn(SequenceUtil.getAppReqSsn());
		
		
		AppCommonResponse<ResponseData> respBean = restRequestService.postToAppForSingleByObj
				("/employee/updateEmployeeInfo"
						, reqBean
						, new TypeToken<AppCommonResponse<ResponseData>>() {}.getType());
		if( respBean != null &&  respBean.getSubCode() != null 
				&& respBean.getSubCode().equals(ReturnCodeConstants.SUB_CODE_SUCC)) {			

			return respBean.getData();
		}else {
			throw new Exception("updateEmployeeInfo error:" + respBean.getSubMsg());
		}
	}

}
